var express = require("express");
var router = express.Router();
const axios = require("axios");

const searchHot = require("../data/searchHot");

router.get("/hot", function (req, res, next) {
  res.json({
    success: true,
    data: searchHot,
  });
});

router.get("/guess", function (req, res, next) {
  res.json({
    success: true,
    data: [
      "澳门六大博彩巨头转型",
      "工行原纪委书记",
      "尹锡悦手机通话记录",
      "快船3人得分20+险胜",
      "俄宣布金砖伙伴国名单",
      "一部爆款短剧 谁能真正赚到钱",
      "退休人员基本养老金",
      "人生一倍速",
      "吴英杰被决定逮捕",
      "'地沟油'身价狂飙",
    ],
  });
});

router.post("/searchSug", function (req, res, next) {
  const { query } = req.body;

  if (query) {
    axios
      .post(
        "https://i.news.qq.com/searchSug",
        {
          query: query,
          devid: "8gAc3H5c7IAdvD3b4Qd3",
        },
        {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded",
          },
        }
      )
      .then((response) => {
        res.json({
          success: true,
          data: response.data,
        });
      });
  } else {
    res.json({
      success: false,
      msg: "参数错误",
    });
  }
});

router.post("/result", function (req, res, next) {
  const { query } = req.body;

  if (query) {
    axios
      .post(
        "https://i.news.qq.com/gw/pc_search/result",
        {
          page: 0,
          query: query,
          is_pc: 1,
          hippy_custom_version: 24,
          search_type: "all",
          search_count_limit: 10,
          appver: "15.5_qqnews_7.1.80",
        },
        {
          headers: {
            "Content-Type": "application/x-www-form-urlencoded",
          },
        }
      )
      .then((response) => {
        res.json({
          success: true,
          data: response.data,
        });
      });
  } else {
    res.json({
      success: false,
      msg: "参数错误",
    });
  }
});

module.exports = router;
